<?php

class ZFBootstrap_Form extends ZFKiller_Form {

    const FORM_TYPE_CAD = 'cad';
    const FORM_TYPE_EDIT = 'edit';
    const FORM_TYPE_READONLY = 'readonly';

    private $_formName;
    protected $_typeForm;

    public function __construct ($formName, $options = null) {
	if (!isset($options['class'])) {
	    $options['class'] = 'form-horizontal';
	}
	if (!isset($options['id'])) {
	    $options['id'] = 'frm_' . preg_replace('#[^a-z0-9]#i', '', $formName);
	}
	if (!isset($options['typeForm'])) {
	    $options['typeForm'] = self::FORM_TYPE_CAD;
	}

	parent::__construct($options);

	$this
		->addElementPrefixPath('ZFBootstrap_Form_Decorator', PATH_ZFEXTEND . '/ZFBootstrap/Form/Decorator', Zend_Form::DECORATOR)
		->addDisplayGroupPrefixPath('ZFBootstrap_Form_Decorator', PATH_ZFEXTEND . '/ZFBootstrap/Form/Decorator')
		->setMethod(Zend_Form::METHOD_POST)
	//->removeDecorator('HtmlTag')
	;
	$this->setTypeForm($options['typeForm']);

	$this->_formName = $formName;
    }

    public function addDisplayGroupFooter (array $elements, $options = null) {
	foreach ($elements as $elementName) {
	    $this->getElement($elementName)->removeDecorator('DtDdWrapper');
	}

	if (isset($options['name'])) {
	    $name = $options['name'];
	    unset($options['name']);
	} else {
	    $name = 'footer-group';
	}

	$this->addDisplayGroup($elements, $name, $options);
	$dg = $this->getDisplayGroup($name);
	$dg->removeDecorator('Fieldset');
	$dg->removeDecorator('DtDdWrapper');
	$dg->removeDecorator('HtmlTag');
	/* $dg->addDecorator('HtmlTagGroupFooter', array(
	  'tag' => 'div',
	  'class' => 'box_footer',
	  )); */
    }

    public function getTypeForm () {
	return $this->_typeForm;
    }

    public function loadDefaultDecorators () {
	if ($this->loadDefaultDecoratorsIsDisabled()) {
	    return $this;
	}

	$decorators = $this->getDecorators();
	if (empty($decorators)) {
	    $this->addDecorator('FormElements')
		    //->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
		    ->addDecorator('Form');
	}
	return $this;
    }

    public function setTypeForm ($typeForm) {
	$this->_typeForm = $typeForm;
    }

}